package adapter;

import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import jiyun.com.yiyanmeng.R;

/**
 * Created by Windows on 2019/11/5.
 */

public class YingDaoAdapter extends PagerAdapter {
    public interface MyClick{
        void onClick(View v);
    }
    private MyClick onClickListener;

    public void setOnClickListener(MyClick onClickListener) {
        this.onClickListener = onClickListener;
    }

    private List<View> list;

    public YingDaoAdapter(List<View> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = list.get(position);
        TextView tv = view.findViewById(R.id.yingdao_tiaoguo);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener!=null)
                    onClickListener.onClick(v);

            }
        });
        container.addView(view);

        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        View view = list.get(position);
        container.removeView(view);

    }
}
